#include "Window.h"

Window::Window(WindowClass *pWindowClass, WindowDescription *pDescription)
	: windowClass(pWindowClass), description(pDescription) {
}

Window::~Window() {
}

HWND Window::getHandle() {
	return handle;
}

bool Window::getIsWindowed() {
	return description->getIsWindowed();
}

bool Window::registerClass() {
	if (!RegisterClassEx(windowClass->getWindowClass())) {
		MessageBox(NULL,
			TurnsDataModel::WINDOW_CLASS_REGISTER_ERROR,
			TurnsDataModel::WINDOW_ERROR_TITLE,
			NULL);

		return false;
	}
	return true;
}

bool Window::create() {
	handle = CreateWindow(
		TurnsDataModel::WINDOW_CLASS_NAME,
		description->getTitle(),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		description->getWidth(),
		description->getHeight(),
		NULL,
		NULL,
		description->getInstance(),
		NULL
	);

	if (!handle) {
		WindowOperations::showWin32ErrorMessage();
		return false;
	}
	return true;
}

void Window::show() {
	ShowWindow(handle, description->getShowWindowParam());
	UpdateWindow(handle);
}
